<?php
/**
 * Created by PhpStorm.
 * User: 技术员专用
 * Date: 2019/3/18
 * Time: 11:29
 */

namespace app\index\controller;

use app\common\lib\Util;
use think\Controller;
use think\Request;
use think\view\driver\Think;
use app\common\lib\Redis;

class Send extends Controller
{
    public function index()
    {
        $phone = \request()->param('phone_num');
        if (empty($phone)) {
            return Util::show(0, 'error', ['phone' => $phone]);
        }
        //生成随机数
        $code = rand(1000, 9999);
        //异步发送短信
        $taskData = [
            'method'=>'sendSms',
            'data'=>[
                'phone' => $phone,
                'code' => $code,
                ],
        ];
        $_SERVER['http_server']->task($taskData);
        //发送成功后redis存储
//        $redis = new \Swoole\Coroutine\Redis();
//        $redis->connect(config('redis.host'), config('redis.port'));
//        $redis->set(Redis::smsKey($phone), $code, config('redis.out_time'));
        return Util::show(1, '发送成功', ['phone' => $phone, 'code' => $code]);


    }
}